
import logging
import threading


from high_rotary_evaporation_os.DeviceStateMachines import *
from high_rotary_evaporation_os.ActionExecutor import *

# Configure logging
logging.basicConfig(level=logging.INFO,
                    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)



# ======= Main System Class =======
class LaboratoryAutomationSystem:
    def __init__(self):
        self.global_vars = GlobalVariables()
        self.action_executor = ActionExecutor(self.global_vars)
        self.action_executor = ActionExecutor(self.global_vars)
        self.task_scheduler = TaskScheduler(self.global_vars, self.action_executor)

        # Initialize devices
        self.chromatograph_module = ChromatographModule(self.global_vars)
        self.rotary_evaporation = RotaryEvaporation(self.global_vars)
        # Initialize other devices...

        # Initialize tasks
        self.task_scheduler.initialize_tasks()

        self.logger = logging.getLogger("laboratory_automation_system")

    def start(self) -> None:
        """Start the laboratory automation system"""
        self.logger.info("Starting laboratory automation system")

        # Start the task scheduler in a separate thread
        scheduler_thread = threading.Thread(target=self.task_scheduler.run)
        scheduler_thread.daemon = True
        scheduler_thread.start()

        # Monitor system and handle user input
        try:
            while True:
                # This would be replaced with an actual UI or API
                time.sleep(1)
        except KeyboardInterrupt:
            self.stop()

    def stop(self) -> None:
        """Stop the laboratory automation system"""
        self.logger.info("Stopping laboratory automation system")
        self.task_scheduler.is_running = False


# ======= Main function =======
def main():
    """Main entry point"""
    system = LaboratoryAutomationSystem()
    system.start()

if __name__ == "__main__":
    main()